/*
 * FileName Size.cpp
*/
#include "stdafx.h"
#include "config.h"
#include "size.h"

namespace DeepZoomImage
{
	Size::Size () : width(0), height(0)
	{

	}

	Size::Size (int zero) : width(0), height(0)
	{

	}

	Size::Size (double w, double h)
	{
		this->width = w;
		this->height = h;
	}

	bool Size::IsEmpty () const
	{
		return (isinf (width) == -1 && isinf (height) == -1);
	}

	Size Size::Max (double w, double h) const
	{
		return Size (width < w ? w : width, height < h ? h : height);
	}

	Size Size::Max (const Size &s) const
	{
		return Max (s.width, s.height);
	}

	Size Size::Min (double w, double h) const
	{
		return Size (width > w ? w : width, height > h ? h : height);
	}

	Size Size::Min (const Size &s) const
	{
		return Min (s.width, s.height);
	}

	Size Size::GrowBy (const double w, const double h) const
	{
		const double hh = isinf (height) ? height : height + h;
		const double ww = isinf (width) ? width : width + w;

		return Size (ww > 0 ? ww : 0, hh > 0 ? hh : 0);
	}

	Size Size::GrowBy (const Thickness &t) 
	{
		return GrowBy (t.left + t.right, t.top + t.bottom);
	}

	bool Size::operator == (const Size &size) const
	{
		return fabs (size.width-width) < DBL_EPSILON && fabs (size.height-height) < DBL_EPSILON;
	}

	bool Size::operator != (const Size &size) const
	{
		return !(*this == size);
	}

	bool Size::FromStr (const char *s, Size *size)
	{
		GArray *values = double_garray_from_str (s, 2);

		if (!values)
			return false;

		*size = Size (g_array_index (values, double, 0), g_array_index (values, double, 1));

		g_array_free (values, true);

		return true;
	}
}